package com.zmn.plat.services.impl.order;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.order.Order;
import com.zmn.plat.persistence.interfaces.order.OrderDao;
import com.zmn.plat.services.interfaces.order.OrderService;

/**
 * @uthor nowind
 * @since 2018/9/22 09:50
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderDao orderDao;

    @Override
    public Order findByKey(Integer orderId) {
        return orderDao.findByKey(orderId);
    }

    @Override
    public List<Order> listAll() {
        return orderDao.listAll();
    }

    @Override
    public Integer updateByKey(Order order) {
        if (order.getUpdateTime() == null) {
            order.setUpdateTime(DateUtil.getNow());
        }
        return orderDao.updateByKey(order);
    }

    @Override
    public Integer insert(Order order) {

        if (order.getUpdateTime() == null) {
            order.setUpdateTime(DateUtil.getNow());
        }
        order.setCreateTime(order.getUpdateTime());

        return orderDao.insert(order);
    }

    @Override
    public void deleteByKey(Integer orderId) {
        orderDao.deleteByKey(orderId);
    }
}
